import { reqLogin } from '@/api/user'
import { setToken, getToken } from '@/utils/auth'

// import { setToken } from '@/utils/auth'
export default {
  namespaced: true,
  state: {
    token: getToken() || ''
  },
  mutations: {
    setToken(state, token) {
      // 将token存储到vuex中
      state.token = token
      // 将token存储到cookie中持久化
      setToken(token)
    }
  },
  actions: {
    async login({ commit }, loginForm) {
      const res = await reqLogin(loginForm)
      console.log(res)
      commit('setToken', res.data)
    }
  }
}
